<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript">
        function onclickway(){
            var a = document.getElementById("123");
            var b = /^\w{5,12}$/;
            
            if (b.test(a.value)){
                alert("用户名合法！");
            }    
            else{
                alert("用户名不合法！");
            }     
        }
    </script>
</head>
<body>
    用户名称：<input type="text" id="123">
    <input type="button" value="确定" onclick="onclickway();">
</body>
</html>